var form,$,table,layer,upload,node;
var user = JSON.parse(localStorage.getItem("user"));
var userId = user.userId;
layui.use(['form','jquery','table','layer','upload'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    upload = layui.upload;

    //获取微圈数目
    getMicrocircleNums()
    //获取微圈列表数据
    getMicrocircleList('','','','');
});

$(".btn").on("click","button",function () {
    $(this).removeClass("layui-btn-primary").siblings("button").addClass("layui-btn-primary");
});
$(".btn").on("mouseover","button",function () {
    $(this).css("border-color","#d2d2d2");
});

//获取微圈数目
function getMicrocircleNums(){
    $.ajax({
        url:'/toExamine/getMicrocircleNums',
        type: "post",
        dataType:'json',
        data: {},
        success:function (data) {
            console.log(data.data);
            $("#allMicrocircleNums").text(data.data.allMicrocircleNums);
            $("#microcircleAdoptNums").text(data.data.microcircleAdoptNums);
            $("#microcircleWaitNums").text(data.data.microcircleWaitNums);
            $("#microcircleNoAdoptNums").text(data.data.microcircleNoAdoptNums);
        }
    });
}
////获取微圈列表信息
function getMicrocircleList(result, artcleTitle, createDate, trueName){
    $.ajax({
        url:'/toExamine/getAllMicroCircle',
        type: "post",
        dataType:'json',
        data: {
            "result": result,
            "artcleTitle": artcleTitle,
            "createDate": createDate,
            "trueName": trueName,
        },
        success:function (data) {
            //展示table表格
            showMicrocircleList(data.data);
        }
    });
}

function showMicrocircleList(data) {
    table.render({
        elem: "#demo",
        data: data,
        toolbar:'#toolutil',
        page: true,
        limit: 10,
        cols:[[
            {title:'序号', align:'center',unresize:true, templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'serialNumber',title:'微圈编号', align:'center',unresize:true},
            {field:'artcleUrl',title:'微圈图片',align:'center',unresize:true, templet:function(data){
                    return "<img src=' " + data.artcleUrl  + " '>";
                }},
            {field:'artcleTitle',title:'微圈名称',align:'center',unresize:true},
            {field:'trueName',title:'用户昵称',align:'center',unresize:true},
            {field:'artcleCategroyName',title:'微圈分类',align:'center',unresize:true},
            {field:'result',title:'审核状态',align:'center',unresize:true, templet:function (data) {
                    if (data.result == 1){
                        return '审核通过';
                    }else if (data.result == 2){
                        return '待审核';
                    }else if (data.result == 3) {
                        return '审核驳回';
                    }
                }},
            {title:'操作',align:'center',unresize:true, templet:function(data){
                    if (data.result == 1){
                        return "<a href='JavaScript:selectMicroCircle(\"" + data.microcircleId +  "\");' class='operation'>查看</a>";
                    } else if (data.result == 2){
                        return "<a href='JavaScript:selectMicroCircle(\"" + data.microcircleId +  "\");' class='operation'>查看</a>" + '&nbsp;&nbsp;'
                            +"<a class='operation' href='javascript:judge(\"" + data.toExamineId + "\", \"" + data.artcleTitle + "\", \"" + data.microcircleId + "\");'>审核</a>";
                    } else if (data.result == 3) {
                        return "<a href='JavaScript:selectMicroCircle(\"" + data.microcircleId +  "\");' class='operation'>查看</a>";
                    }
                }},
        ]]
    });
}

//查看微圈审核
function  selectMicroCircle(microcircleId) {
    $('#proId').val(microcircleId);
    layer.open({
        type: 2,
        content: "/toexamine/microCircle/selectMicroCircle.html",
        area: ['1100px','500px'],
        end: function () {

        }
    });
}

//审核
function judge(id, title, microcircleId){
    $('#proId').val(id);
    $('#proName').val(title);
    $('#microcircleId').val(microcircleId);
    layer.open({
        type:2,
        area:['540px','350px'],
        content:"/toexamine/microCircle/toExamine.html",
    });
}

//搜索
$("#selMicroCircle").on("click",function () {
    var artcleTitle = $("input[name=artcleTitle]").val();
    var createDate = $("input[name=createDate]").val();
    var trueName = $("input[name=trueName]").val();
    getMicrocircleList('',artcleTitle,createDate,trueName);
});
//刷新
function refresh() {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}